
unit emirama;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, fcButton, fcImgBtn, fcShapeBtn, fcClearPanel,
  fcButtonGroup, ComCtrls, Buttons, Grids, Wwdbigrd, Wwdbgrid, Db, ADODB,
  wwdbdatetimepicker, wwdblook, cxStyles, cxCustomData, cxGraphics,                                                 
  cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGrid, cxDBLookupComboBox, Mask, wwdbedit, siComp,
  siLngLnk;

type
  Tfemirarama = class(TForm)
    StatusBar: TStatusBar;
    Panel1: TPanel;
    Edit2: TEdit;
    Edit1: TEdit;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    Edit3: TEdit;
    wwDBDateTimePicker1: TwwDBDateTimePicker;
    CheckBox4: TCheckBox;
    Panel2: TPanel;
    bkapat: TBitBtn;
    baktar: TBitBtn;
    blistele: TBitBtn;
    depoc: TCheckBox;
    AmbarUretimQ: TADOQuery;
    depok: TwwDBLookupCombo;
    UnityEmirNoc: TCheckBox;
    UnityEmirNok: TEdit;
    aqDepolar: TADOQuery;
    cxgrid1: TcxGrid;
    cxgrid1DBTableView1: TcxGridDBTableView;
    cxgrid1Level1: TcxGridLevel;
    cxgrid1DBTableView1emirno: TcxGridDBColumn;
    cxgrid1DBTableView1tarih: TcxGridDBColumn;
    cxgrid1DBTableView1ozelkod1: TcxGridDBColumn;
    cxgrid1DBTableView1miktar: TcxGridDBColumn;
    cxgrid1DBTableView1cinsi: TcxGridDBColumn;
    cxgrid1DBTableView1stokkodu: TcxGridDBColumn;
    cxgrid1DBTableView1girdidepo: TcxGridDBColumn;
    cxgrid1DBTableView1ciktidepo: TcxGridDBColumn;
    cxgrid1DBTableView1unityemirno: TcxGridDBColumn;
    dsDepolar: TDataSource;
    chMiktar: TCheckBox;
    edMik1: TwwDBEdit;
    edMik2: TwwDBEdit;
    Label1: TLabel;
    chTumu: TCheckBox;
    procedure bkapatClick(Sender: TObject);
    procedure baktarClick(Sender: TObject);
    procedure blisteleClick(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure Edit3Change(Sender: TObject);
    procedure Grid1DblClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure wwDBDateTimePicker1Change(Sender: TObject);
    procedure Grid1KeyPress(Sender: TObject; var Key: Char);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure FormShow(Sender: TObject);
    procedure tus(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure depokChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  femirarama: Tfemirarama;
  siras: string;
  bk: string[5];

implementation

uses data, uremri, ana1, UnitOrtak;

{$R *.DFM}

procedure Tfemirarama.bkapatClick(Sender: TObject);
begin
  modalresult := mrcancel;
end;

procedure Tfemirarama.baktarClick(Sender: TObject);
begin
  Grid1DblClick(sender);
  furemri.bak := true;
  modalresult := mrok;
end;

procedure Tfemirarama.blisteleClick(Sender: TObject);
begin
  dm.emirara.Close;
  dm.emirara.sql.Clear;
  dm.emirara.SQL.Add('select ' + ifthen(chTumu.Checked, '', ' Top 3000 ') + ' * from uremri');
  dm.emirara.SQL.Add('where 1=1 ');

  if (chMiktar.Checked) and (Trim(edMik1.Text) <> '') then
    dm.emirara.SQL.Add(' And Miktar >= ' + edMik1.Text);

  if (chMiktar.Checked) and (Trim(edMik2.Text) <> '') then
    dm.emirara.SQL.Add(' And Miktar <= ' + edMik2.Text);

  if CheckBox1.Checked then
    dm.emirara.SQL.Add(' And Stokkodu like ''' + edit1.Text + '%'' ');

  if CheckBox2.Checked then
    dm.emirara.SQL.Add(' And cinsi like ''' + edit2.Text + '%'' ');

  if UnityEmirNoc.Checked then
    dm.emirara.SQL.Add(' And UnityEmirNo=' + UnityEmirNok.Text);

  if CheckBox3.Checked then
    dm.emirara.SQL.Add(' And emirno=' + edit3.Text);

  if CheckBox4.Checked then
    dm.emirara.SQL.Add(' And tarih = :tarih');

  if CheckBox4.Checked then
    dm.emirara.Parameters.ParamByName('Tarih').value := wwDBDateTimePicker1.Date;
  if depoc.Checked then
    dm.emirara.SQL.Add(' And ciktidepo =' + depok.lookupvalue);

  dm.emirara.SQL.Add(' order by emirno desc  ');
  dm.emirara.Open;

  if dm.emirara.RecordCount > 0 then
    cxgrid1.setfocus;
end;

procedure Tfemirarama.Edit1Change(Sender: TObject);
begin
  if trim(Edit1.text) = '' then
    CheckBox1.Checked := false
  else
    CheckBox1.Checked := true;
end;

procedure Tfemirarama.Edit2Change(Sender: TObject);
begin
  if trim(Edit2.text) = '' then
    CheckBox2.Checked := false
  else
    CheckBox2.Checked := true;
end;

procedure Tfemirarama.Edit3Change(Sender: TObject);
begin
  if trim(Edit3.text) = '' then
    CheckBox3.Checked := false
  else
    CheckBox3.Checked := true;
end;

procedure Tfemirarama.Grid1DblClick(Sender: TObject);
begin
  dm.UrEmri.Close;
  dm.UrEmri.Parameters.ParamByName('emirno').value := dm.emirara.fieldbyname('Emirno').value;
  dm.UrEmri.Open;

  dm.UrEmriHar.Close;
  dm.UrEmrihar.Parameters.ParamByName('emirno').value := dm.emirara.fieldbyname('Emirno').value;
  dm.UrEmrihar.Open;

  furemri.bak := true;
  modalresult := mrok;
end;

procedure Tfemirarama.FormClose(Sender: TObject; var Action: TCloseAction);
begin
//  action := cafree;
//  femirarama := nil;
end;

procedure Tfemirarama.wwDBDateTimePicker1Change(Sender: TObject);
begin
  if trim(wwDBDateTimePicker1.text) = '' then
    CheckBox4.Checked := false
  else
    CheckBox4.Checked := true;
end;

procedure Tfemirarama.Grid1KeyPress(Sender: TObject; var Key: Char);
begin
  if key = #13 then
  begin
    dm.UrEmri.Close;
    dm.UrEmri.Parameters.ParamByName('emirno').value := dm.emirara.fieldbyname('Emirno').value;
    dm.UrEmri.Open;

    dm.UrEmriHar.Close;
    dm.UrEmrihar.Parameters.ParamByName('emirno').value := dm.emirara.fieldbyname('Emirno').value;
    dm.UrEmrihar.Open;

    furemri.bak := true;
    modalresult := mrok;
  end;
end;

procedure Tfemirarama.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if key = #27 then close;
end;

procedure Tfemirarama.FormShow(Sender: TObject);
var
  EmirNo: integer;
  asd: Boolean;
begin
  anaform.CreateExport(Self);

  AmbarUretimQ.Open;
  aqDepolar.Open;

  if dm.emirara.active = False then
  begin
    dm.emirara.Close;
    dm.emirara.sql.Clear;
    dm.emirara.SQL.Add('select top 500 * from uremri');
    dm.emirara.SQL.Add(' order by emirno desc  ');
    dm.emirara.Open;
  end
  else
  begin
    EmirNo := 0;
    if dm.emirara.RecordCount > 0 then
      EmirNo := dm.emirara.Fieldbyname('emirno').value;

//    dm.emirara.Close;
//    dm.emirara.sql.Clear;
//    dm.emirara.SQL.Add('select top 500 * from uremri');
//    dm.emirara.SQL.Add(' order by emirno desc  ');
//    dm.emirara.Open;

    if EmirNo <> 0 then
    begin
      dm.emirara.Locate('emirno', EmirNo, []);
//      cxgrid1DBTableView1.DataController.
//      cxgrid1DBTableView1.DataController.FindRecordIndexByKey(EmirNo), asd);
    end;

    edit3.setfocus;
  end;

  Edit3.Setfocus;
end;

procedure Tfemirarama.tus(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = vk_return then
    blistele.Click;

  if (key = vk_down) then
  begin
    Keybd_event(VK_TAB, 0, 0, 0);
    Keybd_event(VK_TAB, 0, KEYEVENTF_KEYUP, 0);
  end;

  if (key = vk_up) then
  begin
    Keybd_event(VK_SHIFT, 0, 0, 0);
    Keybd_event(VK_TAB, 0, 0, 0);
    Keybd_event(VK_TAB, 0, KEYEVENTF_KEYUP, 0);
    Keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
  end;
  key := 0;

end;

procedure Tfemirarama.depokChange(Sender: TObject);
begin
  if trim(depok.text) = '' then
    depoc.Checked := false
  else
    depoc.Checked := true;
end;

end.

